package com.example.system.controller;

import com.example.core.controller.BaseController;
import com.example.core.entity.PageDataInfo;
import com.example.core.result.Res;
import com.example.system.entity.DTO.QuestionAddDTO;
import com.example.system.entity.DTO.QuestionEditDTO;
import com.example.system.entity.DTO.QuestionQueryDTO;
import com.example.system.entity.VO.QuestionDetailVO;
import com.example.system.entity.VO.QuestionVO;
import com.example.system.service.IQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/question")
public class QuestionController extends BaseController {
    @Autowired
    private IQuestionService questionService;

    @GetMapping("/list")
    public PageDataInfo<QuestionVO> list(QuestionQueryDTO questionQueryDTO) {
        return super.getPageDataInfo(questionService.list(questionQueryDTO));
    }

    @PutMapping("/edit")
    public Res<Void> edit(@RequestBody QuestionEditDTO questionEditDTO) {
        return super.toR(questionService.edit(questionEditDTO));
    }

    @GetMapping("/detail")
    public Res<QuestionDetailVO> detail(@RequestParam(value = "questionId") Long questionId) {
        return Res.ok(questionService.detail(questionId));
    }

    @DeleteMapping("/delete")
    public Res<Void> delete(@RequestParam(value = "questionId") Long questionId) {
        return super.toR(questionService.delete(questionId));
    }

    @PostMapping("/add")
    public Res<Void> add(@RequestBody QuestionAddDTO questionAddDTO) {
        return toR(questionService.add(questionAddDTO));
    }

}
